<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<!DOCTYPE html>
<html lang="en">
<head>
<title><s:message code="app.title" /></title>
<%@ include file="Include.jsp"%>
<script type="text/javascript">
	
	$(document).ready(function() {
		var oTable = $('#companyTable').dataTable( {
			 	"bDestroy": true,
		        "bProcessing": false,
		        "iDisplayLength": 10,
		        "bFilter": false,
		        "bLengthChange": false,
		        "aoColumnDefs": [
		          { 'bSortable': false, 'aTargets': [7] }
		       	]
		 	} );
		
		$('#addCompany').click(function(){
			$('#companyListForm').attr('action','AddCompany');
			$('#companyListForm').attr('method','get');
			$('#companyListForm').submit();
		});
		
	});
	
	function edit(companyId){
		$('#companyEditForm').attr('action','EditCompany?companyId='+companyId);
		
		$('#companyId').val(companyId);
		
		$('#companyEditForm').attr('method','get');
		$('#companyEditForm').submit();
	}
	
</script>
</head>
<body>
	<div class="container">
		<%@ include file="Menu.jsp"%>
		<h2><s:message code="companyForm.listheader" /></h2>
		<hr>
		<form:form id="companyEditForm" >
			<input type="hidden" id="companyId" name="companyId" />
		</form:form>
		<form:form id="companyListForm" >
		<c:if test="${not empty successMessage}">
			<div class="alert alert-success">
				${successMessage}
			</div>
		</c:if>
		<table class="table table-hover table-bordered" id="companyTable">
				<thead>
					<tr>
						<th><s:message code="companyForm.companyname" /></th>
						<th><s:message code="companyForm.cityName" /></th>
						<th><s:message code="companyForm.ctcperson" /></th>
						<th><s:message code="companyForm.email" /></th>
						<th><s:message code="companyForm.cellno" /></th>
						<th><s:message code="companyForm.website" /></th>
						<th><s:message code="companyForm.isactive" /></th>
						<th><s:message code="companyForm.creationdate" /></th>
						<th><s:message code="app.action" /></th>
					</tr>
				</thead>
				
				<tbody>
					<c:if test="${empty companyList}">
						<tr>
							<td colspan="8">
								<s:message code="app.norecordsfound" />
							</td>
						</tr>
					</c:if>
					<c:forEach items="${companyList}" var="company" >
						<tr>
							<td>
								<c:out value="${company.companyname}"></c:out>
							</td>
							<td>
								<c:out value="${company.city.cityname}"></c:out>
							</td>
							<td>
								<c:out value="${company.ctcperson}"></c:out>
							</td>
							<td>
								<c:out value="${company.email}"></c:out>
							</td>
							<td>
								<c:out value="${company.cellno}"></c:out>
							</td>
							<td>
								<c:out value="${company.website}"></c:out>
							</td>
							<td>
								<c:choose>
								    <c:when test="${company.isactive == 1}">
								       YES
								    </c:when>
								    <c:otherwise>
								        NO
								    </c:otherwise>
								</c:choose>
							</td>
							<td>
								<fmt:formatDate value="${company.creationdate}" pattern="dd/MM/yyyy"/>
							</td>
							<td>
								<a href="#" onclick="javascript: edit('${company.companyid}');" >Edit</a>
							</td>
						</tr>
					</c:forEach>
				</tbody>
		</table>
		<br>
		<br>
		<br>
		<button class="btn btn-primary" type="button" id="addCompany"><s:message code="companyForm.addheader" /></button>
		</form:form>
		 <%@ include file="Footer.jsp"%>
	</div>
</body>
</html>